/**
 * 
 */
package co.gov.medellin.sdep.sisdep.operativa.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.operativa.exception.ComparendoSegContException;
import co.gov.medellin.sdep.sisdep.operativa.exception.ComparendoSegContRuntimeException;
import co.gov.medellin.sdep.sisdep.operativa.exception.descriptor.ComparendoSegContMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.ComparendoSegCont;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IComparendoSegContDAOT;

/**
 * @author Usuario
 *
 */
public class ComparendoSegContServiceImpl extends BaseService implements IComparendoSegContService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private IComparendoSegContDAOT comparendoSegContDAO;

	/**
	 * 
	 */
	public ComparendoSegContServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(ComparendoSegCont comparendoSegCont) throws ComparendoSegContException {
		try{
			comparendoSegCont.setUsuarioCrea(getPrincipalUser());
			comparendoSegCont.setFechaCrea(new Date());
			getComparendoSegContDAO().insert(comparendoSegCont);
		}catch (Exception e) {
			Object [] infoError = {
				comparendoSegCont.getCodigo()
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new ComparendoSegContException(new ComparendoSegContMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new ComparendoSegContException(new ComparendoSegContMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(ComparendoSegCont comparendoSegCont) throws ComparendoSegContException {
		try{
			comparendoSegCont.setUsuarioModifica(getPrincipalUser());
			comparendoSegCont.setFechaModifica(new Date());
			getComparendoSegContDAO().update(comparendoSegCont);
		}catch (Exception e) {
			Object [] infoError = {
				comparendoSegCont.getCodigo()
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new ComparendoSegContRuntimeException(new ComparendoSegContMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new ComparendoSegContRuntimeException(new ComparendoSegContMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(ComparendoSegCont comparendoSegCont) throws ComparendoSegContException {
		try {
			comparendoSegCont.setUsuarioModifica(getPrincipalUser());
			comparendoSegCont.setFechaModifica(new Date());
			getComparendoSegContDAO().delete(comparendoSegCont);
		}catch (Exception e) {
			Object [] infoError = {
				comparendoSegCont.getCodigo()
			};
			throw new ComparendoSegContRuntimeException(new ComparendoSegContMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, ComparendoSegCont comparendoSegCont) throws ComparendoSegContException {
		try{
			//return getComparendoSegContDAO().getAllComparendoSegContPaginated(start, max, criteria);
			return getComparendoSegContDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new ComparendoSegContRuntimeException(new ComparendoSegContMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List loadByRadicado(int start,int max, ComparendoSegCont comparendoSegCont) throws ComparendoSegContException {
		try{
			//return getComparendoSegContDAO().getAllComparendoSegContPaginated(start, max, criteria);
			return getComparendoSegContDAO().loadByRadicado(comparendoSegCont);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new ComparendoSegContRuntimeException(new ComparendoSegContMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final ComparendoSegCont get(long id) throws ComparendoSegContException {
		try{
			return getComparendoSegContDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new ComparendoSegContRuntimeException(new ComparendoSegContMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public IComparendoSegContDAOT getComparendoSegContDAO() {
		return comparendoSegContDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setComparendoSegContDAO(IComparendoSegContDAOT comparendoSegContDAO) {
		this.comparendoSegContDAO = comparendoSegContDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
